package com.example.basic.handler;

import com.example.basic.exception.CustomException;
import com.example.basic.reslut.ExceptionResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = CustomException.class)
    @ResponseBody
    public ExceptionResponse customExceptionHandler(HttpServletRequest req, CustomException e) {
        return ExceptionResponse.error(e);
    }
}
